package com.xielaoban.his1.controller;

import com.xielaoban.his1.common.ServerResponse;
import com.xielaoban.his1.model.Department;
import com.xielaoban.his1.service.IDepartmentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping(value = "/his1/department/")
@Api(value = "科室管理接口测试器")
public class DepartmentController {

    //依赖注入service/业务层
    @Autowired
    private IDepartmentService iDepartmentService;

    //添加科室
    //通过localhost:8080/his1/add.do
    @ApiOperation(value = "添加科室",notes = "需要添加除了id和删除标记之外的全部参数")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType="add", name = "DeptCode", value = "科室编码", required = true, dataType = "string"),
            @ApiImplicitParam(paramType="add", name = "DeotName", value = "科室名称", required = true, dataType = "string"),
            @ApiImplicitParam(paramType="add", name = "DeptCategoryID", value = "科室分类", required = true, dataType = "int"),
            @ApiImplicitParam(paramType="add", name = "DeptType", value = "科室类型", required = true, dataType = "int")
    })
    @RequestMapping(value = "add.do")
    public ServerResponse addDepartment(Department department){
        return iDepartmentService.add(department);
    }

    //查询所有
    @RequestMapping(value = "selectAll.do")
    public ServerResponse selectAll(){
        return iDepartmentService.selectAll();
    }

    //更新记录
    @RequestMapping(value = "update.do")
    public ServerResponse update(Department department){
        return iDepartmentService.update(department);
    }

    //删除记录
    @RequestMapping(value = "delete.do")
    public ServerResponse deleteOneById(Department department){
        return iDepartmentService.deleteOneById(department);
    }
    //搜索科室，根据科室编号或者科室名称
    @RequestMapping(value = "search.do")
    public ServerResponse search(String keywords, @RequestParam(name = "pagenum",defaultValue = "1")int pagenum,@RequestParam(name = "pagesize",defaultValue = "10")int pagesize){
        return iDepartmentService.qurryByDeptCodeAndDeptName(keywords,pagenum,pagesize);
    }

}
